package com.dong.es.entity.searchparam.agg;

import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
import co.elastic.clients.elasticsearch.core.SearchRequest;
import com.dong.es.entity.EsBaseDTO;
import com.dong.es.entity.searchparam.EsSearchParam;

import java.util.Map;

/**
 * @description: Es 聚合相关参数
 * @author: 陈瑞东
 * @create: 2022-07-07 10:32
 */
public abstract class EsAggsParam<R> extends EsSearchParam<SearchRequest.Builder> {
    private static final long serialVersionUID = 846221033489233724L;

    // 聚合名称
    protected String aggName;

    @Override
    protected void addMethod(EsBaseDTO esBaseDTO) {
        setMethod(esBaseDTO);
    }

    @Override
    protected void setMethod(EsBaseDTO esBaseDTO) {
        esBaseDTO.aggregations(this);
    }

    /**
     * 解析聚合结果
     * @param aggregations 聚合结果
     * @return
     */
    public abstract R parseResult(Map<String, Aggregate> aggregations);

    @Override
    public abstract void loadTo(SearchRequest.Builder target);
}
